import 'package:flutter/material.dart';
import 'package:flutter_widget/custom/custom_appbar.dart';

// ignore: must_be_immutable
class DialogPage extends StatefulWidget {
  String name;
  DialogPage({Key? key, required this.name}) : super(key: key);

  @override
  _DialogPageState createState() => _DialogPageState();
}

class _DialogPageState extends State<DialogPage> {
  void showSimpleDialog() async {
    final res = await showDialog(
      context: context,
      builder: (BuildContext context) {
        return SimpleDialog(
          title: const Text('Simple Dialog'),
          children: [
            SimpleDialogOption(
              child: const Text('Option A'),
              onPressed: () {
                Navigator.pop(context, "A");
              },
            ),
            SimpleDialogOption(
              child: const Text('Option B'),
              onPressed: () {
                Navigator.pop(context, "B");
              },
            ),
            SimpleDialogOption(
              child: const Text('Option C'),
              onPressed: () {
                Navigator.pop(context, "C");
              },
            ),
          ],
        );
      },
    );
    // ignore: avoid_print
    print(res);
  }

  void showAlertDialog() async {
    final res = await showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: const Text('Alert Dialog'),
          content: const Text('确定删除嘛'),
          actions: [
            // ignore: deprecated_member_use
            ElevatedButton(
              onPressed: () {
                Navigator.pop(context, true);
              },
              child: const Text(
                "确定",
                style: TextStyle(
                  fontSize: 20,
                  color: Colors.white,
                ),
              ),
            ),
            // ignore: deprecated_member_use
            ElevatedButton(
              onPressed: () {
                Navigator.of(context).pop(false);
              },
              child: const Text(
                "取消",
                style: TextStyle(
                  fontSize: 20,
                  color: Colors.white,
                ),
              ),
            ),
          ],
        );
      },
    );

    // ignore: avoid_print
    print(res);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppbar(widget.name, Theme.of(context).primaryColor),
      body: Center(
        child: Column(
          children: [
            // ignore: deprecated_member_use
            ElevatedButton(
              onPressed: showAlertDialog,
              child: const Text(
                "AlertDialog 对话框",
                style: TextStyle(
                  fontSize: 20,
                  color: Colors.white,
                ),
              ),
            ),
            const SizedBox(height: 30),
            // ignore: deprecated_member_use
            ElevatedButton(
              onPressed: showSimpleDialog,
              child: const Text(
                "Dialog 对话框",
                style: TextStyle(
                  fontSize: 20,
                  color: Colors.white,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
